package com.ruoyi.womp.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.womp.domain.WompOsiPlan;
import com.ruoyi.womp.service.IWompOsiPlanService;

/**
 * 巡检计划Controller
 * 
 * @author mzz
 * @date 2023-05-11
 */
@Controller
@RequestMapping("/womp/osiPlan")
public class WompOsiPlanController extends BaseController {
	private String prefix = "womp/osiPlan";

	@Autowired
	private IWompOsiPlanService wompOsiPlanService;

	@RequiresPermissions("womp:osiPlan:view")
	@GetMapping()
	public String osiPlan() {
		return prefix + "/osiPlan";
	}

	/**
	 * 查询巡检计划列表
	 */
	@RequiresPermissions("womp:osiPlan:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WompOsiPlan wompOsiPlan) {
		startPage();
		List<WompOsiPlan> list = wompOsiPlanService.selectWompOsiPlanList(wompOsiPlan);
		return getDataTable(list);
	}

	/**
	 * 导出巡检计划列表
	 */
	@RequiresPermissions("womp:osiPlan:export")
	@Log(title = "巡检计划", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(WompOsiPlan wompOsiPlan) {
		List<WompOsiPlan> list = wompOsiPlanService.selectWompOsiPlanList(wompOsiPlan);
		ExcelUtil<WompOsiPlan> util = new ExcelUtil<WompOsiPlan>(WompOsiPlan.class);
		return util.exportExcel(list, "巡检计划数据");
	}

	/**
	 * 新增巡检计划
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存巡检计划
	 */
	@RequiresPermissions("womp:osiPlan:add")
	@Log(title = "巡检计划", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WompOsiPlan wompOsiPlan) {
		try {
			return toAjax(wompOsiPlanService.insertWompOsiPlan(wompOsiPlan));
		} catch (DuplicateKeyException e) {
			e.printStackTrace();
			return error(e.getMessage());
		}
	}

	/**
	 * 修改巡检计划
	 */
	@RequiresPermissions("womp:osiPlan:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		WompOsiPlan wompOsiPlan = wompOsiPlanService.selectWompOsiPlanById(id);
		mmap.put("wompOsiPlan", wompOsiPlan);
		return prefix + "/edit";
	}

	/**
	 * 修改保存巡检计划
	 */
	@RequiresPermissions("womp:osiPlan:edit")
	@Log(title = "巡检计划", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WompOsiPlan wompOsiPlan) {
		try {
			return toAjax(wompOsiPlanService.updateWompOsiPlan(wompOsiPlan));
		} catch (DuplicateKeyException e) {
			e.printStackTrace();
			return error(e.getMessage());
		}
	}

	/**
	 * 删除巡检计划
	 */
	@RequiresPermissions("womp:osiPlan:remove")
	@Log(title = "巡检计划", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(wompOsiPlanService.deleteWompOsiPlanByIds(ids));
	}
}
